package exec;

import java.util.Random;
import java.util.Scanner;

public class Exec04 {

    public static void main(String[] args) {
        // 给定一个整数数组，输入一个值 n, 输出数组中第 n 大的数。
        int[] arr = {12, 23, 34, 19, 25, 17, 23, 17, 19};
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n > arr.length) {
            System.out.println("输入的有问题，请重新输入：");
            n = sc.nextInt();
        }
        // 排序  选择排序
        for (int i = 1; i < arr.length; i++) {
            int current = arr[i];
            int prevIndex = i - 1;
            for (; prevIndex >=0 && current > arr[prevIndex]; prevIndex --) {
                arr[prevIndex + 1] = arr[prevIndex];
            }
            arr[prevIndex + 1] = current;
        }
//        for (int i = 0; i < arr.length; i++) {
//            int temp = arr[i];
//            int maxIndex = i;
//            for (int j = i + 1; j < arr.length; j++) {
//                if (arr[j] > arr[maxIndex]) {
//                    maxIndex = j;
//                }
//            }
//            arr[i] = arr[maxIndex];
//            arr[maxIndex] = temp;
//        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }
        System.out.println();
        System.out.println("第" + n + "大数字是" + arr[n - 1]);
    }
}
